package com.example.jurisdiction.Service.impl;

import java.util.List;

import com.example.jurisdiction.Mapper.UserMapper;
import com.example.jurisdiction.Service.UserService;
import entity.sys_user_info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceimpl implements UserService {
	
	@Autowired
	private UserMapper userDao;

	@Autowired
	BCryptPasswordEncoder bCryptPasswordEncoder;
	@Override
	public int addUser(sys_user_info u) throws Exception {
		// TODO Auto-generated method stub
		return this.userDao.addUser(u);
	}

	@Override
	public int updateUser(sys_user_info u) throws Exception {
		// TODO Auto-generated method stub
		return this.userDao.updateUser(u);
	}

	@Override
	public int delUser(int id) throws Exception {
		// TODO Auto-generated method stub
		return this.userDao.delUser(id);
	}

	@Override
	public sys_user_info getUser(int id) throws Exception {
		// TODO Auto-generated method stub
		return this.userDao.getUser(id);
	}

	@Override
	public List<sys_user_info> select(String name) throws Exception {
		// TODO Auto-generated method stub
		return this.userDao.select(name);
	}

	@Override
	public List<sys_user_info> getSysUser() throws Exception {
		return this.userDao.getSysUser();
	}

	@Override
	public sys_user_info login(sys_user_info s) throws Exception {

		sys_user_info name=this.userDao.login(s);//数据库名
		System.out.println(name);
		if(name==null){
			return null;
		}else {


			System.out.println("前" + s.getUserPwd());
			System.out.println("后" + name.getUserPwd());
			System.out.println(bCryptPasswordEncoder.matches("456", "$2a$10$MNUrvUSHYBoDgo4nlL42PezEFXvRMn1dRm1ZVLejRSvMakO.J4juG"));
			if (!bCryptPasswordEncoder.matches(s.getUserPwd(), name.getUserPwd())) {
				name = null;
			}
			System.out.println(name);
			return name;
		}

	}

}
